//
//  EditHeader.m
//  便签
//
//  Created by  on 2022/9/29.
//

#import "EditHeader.h"
@interface EditHeader()<UITextViewDelegate>
@property (strong, nonatomic) IBOutlet UIButton *weathBtn;
@property (strong, nonatomic) IBOutlet UIButton *time;
@property (strong, nonatomic) IBOutlet UILabel *placeholder;

@end
@implementation EditHeader

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(NoteModel *)model{
    _model = model;
    NSString *time = [NSDate transToDate:@"HH:mm:ss" :model.stamp];
    [self.time setTitle:time forState:UIControlStateNormal];
    self.inputView.text = model.content;
    self.placeholder.hidden = model.content.length > 0;
    self.inputView.font = [UIFont systemFontOfSize:[model.font floatValue] weight:model.bold ? UIFontWeightBold:UIFontWeightRegular];
    self.inputView.textHexColor = model.hexcolor;
    [self.weathBtn setImage:[UIImage imageNamed:model.weather] forState:UIControlStateNormal];
}
- (IBAction)acionForBtn:(UIButton *)sender {
    if (self.block) {
        if (sender.tag == 201) {
            self.block(sender.tag);
        }
    }
}
#pragma mark - UITextViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    self.placeholder.hidden = YES;
    return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    self.placeholder.hidden = textView.text.length > 0;
    return YES;
}
- (void)textViewDidChangeSelection:(UITextView *)textView{
    self.model.content = textView.text;
}
@end
